package mortal.game.control
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Game.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.player.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlayerRootController extends Controller
    {
        private var _rootModule:PlayerRootModule;

        public function PlayerRootController()
        {
            
        }

        override protected function initView() : IView
        {
            if (this._rootModule == null)
            {
                this._rootModule = new PlayerRootModule();
            }
            return this._rootModule;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.AcupointOpenRootModule, this.onRootModuleOpenHandler);
            Dispatcher.addEventListener(EventName.AcupointUpgradeRoot, this.onUpgradeRootHandler);
            Dispatcher.addEventListener(EventName.AcupointUpgradeRootSuccess, this.onUpgradeRootSuccessHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onBagDataChangehandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateAcupointInfo, this.onAcupointInfoReciveHandler);
            
        }

        private function onRootModuleOpenHandler(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            if (view.isHide)
            {
                _loc_2 = event.data as int;
                this._rootModule.show();
                this._rootModule.setCurrentRoot(_loc_2);
            }
            else
            {
                this._rootModule.hide();
            }
            
        }

        private function onUpgradeRootHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2.step as int;
            var _loc_4:* = _loc_2.useProtect;
            GameProxy.acupoint.upgradeRoot(_loc_3, _loc_4);
            
        }

        private function onUpgradeRootSuccessHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2.step;
            var _loc_4:* = _loc_2.newLevel;
            var _loc_5:* = _loc_2.result;
            var _loc_6:* = _loc_2.acupointAttribute;
            AcupointData.setRootLevel(_loc_3, _loc_4);
            AcupointData.setAttributesByStep(_loc_3, _loc_6);
            this._rootModule.setConfigInfo(_loc_3);
            this._rootModule.setRootInfo(_loc_3);
            if (_loc_5)
            {
                MsgManager.addBroadCast("提升根骨成功");
            }
            else
            {
                MsgManager.addBroadCast("提升根骨失败");
            }
            
        }

        private function onBagDataChangehandler(param1:Object) : void
        {
            if (this._rootModule != null && !this._rootModule.isHide)
            {
                this._rootModule.updateProtectProp();
            }
            
        }

        private function onAcupointInfoReciveHandler(param1:MessageBlock) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = param1.messageBase as SAcupointInfo;
            AcupointData.setInfo(_loc_2);
            if (this._rootModule != null && !this._rootModule.isHide)
            {
                _loc_3 = _loc_2.step;
                if (_loc_3 > 1 && _loc_3 <= 8)
                {
                    _loc_3 = _loc_3 - 1;
                }
                else if (_loc_3 == 1)
                {
                    _loc_3 = 8;
                }
                this._rootModule.updateConfigInfo(_loc_3);
                this._rootModule.updateRootInfo(_loc_3);
            }
            
        }

    }
}
